package dp;

import java.util.Arrays;

public class ChangeMakingProblem {
    //零钱兑换 动态规划
    public static void main(String[] args) {
        coinChange(new int[]{1, 3, 5}, 5);
    }

    private static void coinChange(int[] ints, int acount) {
        int[][] dp = new int[ints.length][acount + 1];
        for (int i = 1; i < acount + 1; i++) {
            //当前背包容量减去当前硬币占用的空间 加上要放入的硬币数
            dp[0][i] = dp[0][i - ints[0]] + 1;
        }

        for (int i = 1; i < ints.length; i++) {
            int IntI = ints[i];
            for (int j = 1; j < acount + 1; j++) {
                if (j >= IntI) {
                    dp[i][j] = Integer.min(dp[i - 1][j], dp[i][j - IntI] + 1);
                } else {
                    dp[i][j] = dp[i - 1][j];
                }
            }
        }

        print(dp);
    }

    private static void print(int[][] dp) {
        System.out.println("=====");
        for (int[] ints : dp) {
            System.out.println(Arrays.toString(ints));
        }
        System.out.println("=====");
    }
}
